package com.coder.algorithm.leetcode

/**
 * [283. 移动零](https://leetcode-cn.com/problems/move-zeroes/)
 *
 * @author yuhus
 * @date: 2022/3/30
 */
object l_0283 {
    fun moveZeroes(nums: IntArray): Unit {
        var slow = 0
        for (fast in nums.indices) {
            if (nums[fast] != 0) {
                var temp = nums[slow]
                nums[slow++] = nums[fast]
                nums[fast] = temp
            }
        }
    }

    fun moveZeroes_1(nums: IntArray): Unit {
        var slow = 0
        for (fast in nums.indices) {
            if (nums[fast] != 0) {
                nums[slow++] = nums[fast]
            }
        }
        for (i in slow until nums.size) {
            nums[i] = 0
        }
    }
}